package com.xinda.admin.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xinda.admin.pojo.Admin;
import com.xinda.admin.pojo.Provider;
import com.xinda.admin.service.ExamineService;
import com.xinda.admin.vo.ExamineVO;

@Controller(value="examineController")
public class ExamineController {
	
	@Resource(name="examineService")
	private ExamineService examineService;
	
	/*
	 * 查询待审核列表	 
	@RequestMapping(value = "/examineList")
	public String examineList(Model model) {
		
		List<Provider> examineProviderList=new ArrayList<Provider>();
		examineProviderList=examineService.sellectExamineProvider();
		model.addAttribute("examineProviderList",examineProviderList);

		return "admin/examine/examineList";
	}
	*/
	
	/**
	 * 查询待审核列表,加入了搜索功能
	 */
	@RequestMapping(value = "/examineList")
	public String examineList(Model model,HttpSession httpSession,String examineName,String datemin,String datemax) {
		Map<String,String> conditionsMap = new HashMap<String,String>();
		conditionsMap.put("examineName", examineName);
		conditionsMap.put("datemin", datemin);
		conditionsMap.put("datemax", datemax);
		List<Provider> examineList = new ArrayList<Provider>();
		
		examineList = examineService.sellectExamineProvider(conditionsMap);
		
		int countExamine = examineService.countExamine();
		model.addAttribute("countExamine", countExamine);
		model.addAttribute("examineList", examineList);
		model.addAttribute("examineName", examineName);
		model.addAttribute("datemin",datemin);
		model.addAttribute("datemax", datemax);
		return "admin/examine/examineList";
	}
	
	/**
	 * 通过前端的复选框，批量通过服务商
	 */
	@RequestMapping(value ="examinesApprove")
	@ResponseBody
	public String examinesApprove(String id) {
		String[] ids = id.split(",");
		examineService.approveExamines(ids);
		return "";
	}
	
		
	/**
	 * 打开审核页面
	 */
	@RequestMapping(value = "/examineShow")
	public String examineShow(Model model,Integer id ) {
		
		Provider examineProvider=examineService.sellectProviderById(id);
		model.addAttribute("examineProvider",examineProvider);
		return "admin/examine/examineShow";
	}
	
	/**
	 * 对服务商进行审核
	 */
	@RequestMapping(value="/examineProvider")
	@ResponseBody
	public String examineProvider(HttpServletRequest request, Model model){
		
		ExamineVO examineVO=new ExamineVO();
		examineVO.setExamineId(Integer.valueOf(request.getParameter("examineId")));
		examineVO.setExamineSuggest(request.getParameter("suggesttext"));
		examineVO.setExamineStatus(Integer.valueOf(request.getParameter("examine")));
		examineService.examineProvider(examineVO);
		
		return "";
	}	
	
	
	/**
	 * 查询未通过审核服务商列表
	 */
	@RequestMapping(value = "/unGoExamineList")
	public String unGoExamineList(Model model) {
		List<Provider> unGoExamineProviderList=new ArrayList<Provider>();
		unGoExamineProviderList=examineService.sellectUnGoExamineProvider();
		model.addAttribute("unGoExamineProviderList",unGoExamineProviderList);
		
		return "admin/examine/unGoExamineList";
	}
	
	/**
	 * 查看不通过页面
	 */
	@RequestMapping(value = "/unGoExamineShow")
	public String unGoExamineShow(Model model,Integer id ) {
		
		Provider examineProvider=examineService.sellectProviderById(id);
		model.addAttribute("examineProvider",examineProvider);
		
		return "admin/examine/unGoExamineShow";
	}
	
	
	
	

		
}
